<template>
	<view>
		<u-tabbar :value="current?current:0" @change="tabbarChange" :fixed="true" :placeholder="false"
			:safeAreaInsetBottom="true" activeColor="#c57f7f">
			<u-tabbar-item :text="item.text" :icon="item.icon" v-for="(item,index) in list" :key="index">
			</u-tabbar-item>
		</u-tabbar>
		<u-toast ref="uToast" />
	</view>
</template>

<script>
	export default {
		props: {
			current: Number
		},
		data() {
			return {
				list: [{
						path: "pages/index/index",
						icon: "home",
						text: "首页"
					}, {
						path: "pages/topic/topic",
						icon: "order",
						text: "专题"
					},
					{
						path: 'pages/category/category',
						icon: "grid",
						text: "分类"
					},
					{
						path: "pages/cart/cart",
						icon: "shopping-cart",
						text: "购物车"
					},
					{
						path: "pages/user/user",
						icon: "account",
						text: "我的"
					}
				]
			};
		},
		methods: {
			tabbarChange(e) {
				let token = uni.getStorageSync('token')
				if (e == 3) {
					if (token) {
						uni.switchTab({
							url: '/' + this.list[e].path,
						})
					} else {
						this.$refs.uToast.show({
							type: 'loading',
							message: "请先登录",
							loading: true,
						})
						setTimeout(() => {
							uni.switchTab({
								url: '/' + this.list[4].path,
							})
						}, 1500)
						uni.setStorageSync('cartUrl', `/${this.list[e].path}`)
						return
					}
				}
				uni.switchTab({
					url: '/' + this.list[e].path,
				})
			},
		},
	}
</script>

<style lang="scss">

</style>
